package com.suyang.mongo.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.suyang.mongo.model.User;
import com.suyang.mongo.service.IUserServiceImpl;

/**
 * System - 用户 - Controller
 * 
 * @author Dwen
 * @version v 0.1 2013-3-17 下午09:00:05
 */
@Controller
public class UserController {
	@Autowired
	private IUserServiceImpl userService;

	/**
	 * 登录
	 */
	@RequestMapping("/mlogin")
	public ModelAndView login(HttpServletRequest request, User user) {
		User user2 = userService.login(user);
		ModelAndView mav = new ModelAndView();
		if (null == user2) {
			mav.setViewName("1");
		} else {
			mav.addObject("user", user2);
			mav.setViewName("2");
		}
		return mav;
	}

	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public String add(HttpServletRequest request, User user) {
		userService.add(user);
		return "1";
	}
}